//
//  StoryTableViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/17.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "StoryTableViewCell.h"
#import "LuBDefine.h"

#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation StoryTableViewCell

- (void)dealloc{
    [_story release];
    [_photoImageView release];
    [_photo_desLabel release];
    [_plnumLabel release];
    [_zanLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createStoryTableViewCell];
    }
    return self;
}

- (void)createStoryTableViewCell{
    self.selectionStyle = 0;
    
    self.photoImageView = [[UIImageView alloc]init];
    self.photoImageView.backgroundColor = [UIColor redColor];
    [self addSubview:_photoImageView];
    [_photoImageView release];
    
    self.photo_desLabel = [[UILabel alloc]init];
//    self.photo_desLabel.backgroundColor = [UIColor orangeColor];
    [self addSubview:_photo_desLabel];
    [_photo_desLabel release];
    
    self.plnumLabel = [[UILabel alloc]init];
//    self.plnumLabel.backgroundColor = [UIColor magentaColor];
    [self addSubview:_plnumLabel];
    [_plnumLabel release];
    
    self.zanLabel = [[UILabel alloc]init];
//    self.zanLabel.backgroundColor = [UIColor greenColor];
    [self addSubview:_zanLabel ];
    [_zanLabel release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _photoImageView.frame = CGRectMake(10, 10, WIDTH - 20, CHEIGHT / 4.1);
    
    _photo_desLabel.frame = CGRectMake(10, 10 + self.photoImageView.frame.size.height + 10, WIDTH / 2, 30);
    _photo_desLabel.font = [UIFont systemFontOfSize:13];
    
    UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(0, _photoImageView.frame.size.height + _photo_desLabel.frame.size.height + 30, WIDTH, 0.5)];
    labelOne.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:labelOne];
    [labelOne release];
    
    _plnumLabel.frame = CGRectMake(WIDTH / 5 * 3, _photoImageView.frame.size.height + self.photo_desLabel.frame.size.height + 20 + 20, WIDTH / 5 + 10, 30);
    _plnumLabel.font = [UIFont systemFontOfSize:13];
    
    _zanLabel.frame = CGRectMake(WIDTH / 5 * 4, _photoImageView.frame.size.height + self.photo_desLabel.frame.size.height + 20 + 20, WIDTH / 5 + 10, 30);
    _zanLabel.font = [UIFont systemFontOfSize:13];
}

- (void)setStory:(Story *)story{
    if (_story != story) {
        [_story release];
        _story = [story retain];
    }
    NSURL *photoUrl = [NSURL URLWithString:story.photo];
    [_photoImageView sd_setImageWithURL:photoUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    _photo_desLabel.text = story.photo_des;
    _plnumLabel.text = [NSString stringWithFormat:@"💬 %@",story.plnum];
    _zanLabel.text = [NSString stringWithFormat:@"👍 %@",story.zan];
    
}

+ (StoryTableViewCell *)storyTableCellWithTableView:(UITableView *)tableView{
    static NSString *storyCell = @"storyCell";
    StoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:storyCell];
    if (!cell) {
        cell = [[[StoryTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:storyCell] autorelease];
    }
    return cell;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
